﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

[Serializable]
public class SerializableDictionary<k, v> : Dictionary<k, v>, ISerializationCallbackReceiver
{
    [SerializeField]private List<k> keys = new List<k>();
    [SerializeField]private List<v> values = new List<v>();

  
    public void OnBeforeSerialize()
    {
        keys.Clear();
        values.Clear();
        foreach (KeyValuePair<k, v> vap in this)
        {
            keys.Add(vap.Key);
            values.Add(vap.Value);
        }
    }

    public void OnAfterDeserialize()
    {
        this.Clear();
        if(keys.Count != values.Count)
        {
            Debug.Log("SerializableDictionary keys count not equal values count!");
        }

        for (int i = 0; i < keys.Count; i++)
        {
            this.Add(keys[i], values[i]);
        }
    }

}

